package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.OrdersDto;
import com.itheima.reggie.pojo.Employee;
import com.itheima.reggie.pojo.Orders;
import com.itheima.reggie.service.OrdersService;
import com.mysql.cj.x.protobuf.MysqlxCrud;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单管理
 */
@RestController
@RequestMapping("order")
public class OrdersController {
    @Autowired
    OrdersService ordersService;

    /**
     * 提交订单
     */
    @PostMapping("submit")
    public R submit(@RequestBody Orders orders){
        ordersService.submitOrder(orders);
        return R.success("下单成功");
    }

    /**
     * 分页查询
     */
    @GetMapping("page")
    public R<Page<Orders>> page( Long page, Long pageSize,String name){
        //1.创建一个分页对象page
        Page<Orders> pageInfo = new Page<>(page,pageSize);
        //2.创建一个条件构造对象

        //分页查询,select * from employee where name = ? order by update_time limit ? ,?
        ordersService.lambdaQuery()
            .like(StringUtils.isNotBlank(name),Orders::getUserName,name) //过滤条件
            .orderByDesc(Orders::getCheckoutTime) //排序条件
            .page(pageInfo);   //分页查询
        //3.响应数据
        return R.success(pageInfo);
    }


}
